.LemonSwitch {
    --lemon-switch-height: 1.125rem;
    --lemon-switch-width: calc(11 / 6 * var(--lemon-switch-height)); // Same proportion as in IconToggle

    display: flex;
    gap: 0.5rem;
    align-items: center;
    width: fit-content;
    font-weight: 500;
    line-height: 1.5rem;

    label[for] {
        cursor: pointer; // A label with for=* also toggles the switch, so it shouldn't have the text select cursor
    }

    label {
        flex: 1;
        cursor: inherit;
    }

    &.LemonSwitch--full-width {
        width: 100%;
        padding-right: 0.5rem;
        padding-left: 0.5rem; // Should be aligned with buttons
    }

    &.LemonSwitch--bordered {
        min-height: calc(2.125rem + 3px); // Medium size button height + button shadow height
        padding: 0 0.75rem;
        line-height: 1.4;
        background: var(--bg-light);
        border: 1px solid var(--border);
        border-radius: var(--radius);

        &.LemonSwitch--small {
            gap: 0.5rem;
            min-height: calc(1.875rem + 3px); // Small size button height + button shadow height
            padding: 0 0.5rem;
        }
    }

    > .LemonIcon {
        font-size: 1.5rem;
        color: var(--muted-alt);
    }

    &.LemonSwitch--disabled {
        cursor: not-allowed;
        opacity: var(--opacity-disabled);

        label[for] {
            cursor: not-allowed; // A label with for=* also toggles the switch, so it shouldn't have the text select cursor
        }
    }
}

.LemonSwitch__button {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: var(--lemon-switch-width);
    height: var(--lemon-switch-height);
    padding: 0;
    cursor: pointer;
    background: none;
    border: none;

    .LemonSwitch--disabled & {
        cursor: not-allowed;
    }
}

.LemonSwitch__slider {
    position: absolute;
    top: 0;
    left: 0;
    display: inline-block;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-color: var(--border-bold);
    border-radius: var(--lemon-switch-height);
    transition: background-color 100ms ease;

    .LemonSwitch--checked & {
        background-color: var(--primary-3000);
    }
}

.LemonSwitch__handle {
    --lemon-switch-handle-ratio: calc(3 / 4); // Same proportion as in IconToggle
    --lemon-switch-handle-gutter: calc(var(--lemon-switch-height) * calc(1 - var(--lemon-switch-handle-ratio)) / 2);
    --lemon-switch-handle-width: calc(var(--lemon-switch-height) * var(--lemon-switch-handle-ratio));
    --lemon-switch-active-translate: translateX(
        calc(var(--lemon-switch-width) - var(--lemon-switch-handle-width) - var(--lemon-switch-handle-gutter) * 2)
    );

    position: absolute;
    top: var(--lemon-switch-handle-gutter);
    left: var(--lemon-switch-handle-gutter);
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--lemon-switch-handle-width);
    height: calc(var(--lemon-switch-height) * var(--lemon-switch-handle-ratio));
    pointer-events: none;
    cursor: inherit;
    background-color: #fff;
    border: none;
    border-radius: 0.625rem;
    transition: background-color 100ms ease, transform 100ms ease, width 100ms ease, border-color 100ms ease;

    .LemonSwitch--checked & {
        background-color: #fff;
        border-color: var(--primary-3000);
        transform: var(--lemon-switch-active-translate);
    }

    .LemonSwitch--active & {
        --lemon-switch-handle-width: calc(var(--lemon-switch-height) * var(--lemon-switch-handle-ratio) * 1.2);

        transform: none;
    }

    .LemonSwitch--active.LemonSwitch--checked & {
        transform: var(--lemon-switch-active-translate);
    }
}
